<?php
	session_start();
	header('Content-type: text/javascript');

	$demoLangFile = $_SERVER['DOCUMENT_ROOT'].'/lang/demos/complete.xml';
	$eventsFile = $_SERVER['DOCUMENT_ROOT'].'/lang/events-calendar.xml';

	switch ($_SERVER['HTTP_HOST']){
		case "127.0.0.1:30000":
			$demoLangFile = $_SERVER["DOCUMENT_ROOT"].'/lang/demos/complete.xml';
			break;
		case "67.23.1.23":
			$demoLangFile = './lang/demos/complete.xml';
			break;
	}
	if (isset($_SESSION['lang']))
	{
		switch ($_SESSION['lang']) {
			case "zh-tw" :
				$demoLangFile = $_SERVER["DOCUMENT_ROOT"].'/lang/demos/zh-tw.xml';
				break;
			case "ja-jp" : 
				$demoLangFile = $_SERVER["DOCUMENT_ROOT"].'/lang/demos/ja-jp.xml';
				break;
			case "euc-kr" : 
				$demoLangFile = $_SERVER["DOCUMENT_ROOT"].'/lang/demos/euc-kr.xml';
				break;
		}
	}
	
	if (file_exists($demoLangFile)) {
		$xml = file_get_contents($demoLangFile);
		$xml = preg_replace('/\t/', '', $xml);
		$xml = str_replace(array("\r\n", "\n", "\r"), '', $xml);
		$xml = str_replace("'", '&rsquo;', $xml);

		// Convert CDATA into xml nodes.
		$xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA);

		$json = json_encode($xml);

		echo "var demojson = " . $json . ";";
	}
	if (file_exists($eventsFile)) {
		$xml = file_get_contents($eventsFile);
		$xml = preg_replace('/\t/', '', $xml);
		$xml = str_replace(array("\r\n", "\n", "\r"), '', $xml);
		$xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA);
		$json = json_encode($xml);

		echo "var calendarJson = " . $json . ";";
	}

?>